package com.zou.controller.proscenium.common;

import com.zou.pojo.Info;
import com.zou.pojo.MaxMenu;
import com.zou.pojo.MinMenu;
import com.zou.service.InfoService;
import com.zou.service.MaxMenuService;
import com.zou.service.MinMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

import java.util.ArrayList;
import java.util.List;

public class InitCommon {
    private InfoService infoService;
    private MaxMenuService maxMenuService;
    private MinMenuService minMenuService;
    private Model model;

    public InitCommon(InfoService infoService, MaxMenuService maxMenuService, MinMenuService minMenuService, Model model) {
        this.infoService = infoService;
        this.maxMenuService = maxMenuService;
        this.minMenuService = minMenuService;
        this.model = model;
    }

    public Model initHtml() {
        // 导航栏
        List<MaxMenu> maxMenuList = maxMenuService.querySomeMaxMenuByMaxMenu(new MaxMenu());
        model.addAttribute("maxMenuList", maxMenuList);

        // 下拉导航栏
        List minMenuList = new ArrayList<>();
        for (MaxMenu maxMenu : maxMenuList) {
            List<MinMenu> minMenus = minMenuService.querySomeMinMenuByMinMenu(
                    new MinMenu().setMaxId(maxMenu.getMaxId()));
            minMenuList.add(minMenus);
        }
        model.addAttribute("minMenuList", minMenuList);

        // 侧边栏
        List<Info> infoList3 = infoService.queryInfoByMaxId(3);
        model.addAttribute("infoList3", infoList3);
        List<Info> infoList4 = infoService.queryInfoByMaxId(4);
        model.addAttribute("infoList4", infoList4);

        return model;
    }
}
